<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>表单 | CatchAdmin 官网</title>
    <meta name="description" content="">
    <meta name="generator" content="VuePress 1.8.2">
    <style>a[title="站长统计"]{display:none}</style>
    <script data-ad-client="ca-pub-1505209242532150" async="true" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script src="https://v1.cnzz.com/z_stat.php?id=1279921342&amp;web_id=1279921342"></script>
    <meta name="description" content="基于 Thinkphp & Vue 开发的后台管理框架">
    <meta name="keywords" content="catchadmin, 后台管理, 前后端分离, thinkphp后台管理框架, thinkphp前后端分离框架,php, elementui">
    <link rel="preload" href="/assets/css/0.styles.6834c255.css" as="style"><link rel="preload" href="/assets/js/app.d0396f44.js" as="script"><link rel="preload" href="/assets/js/2.1cef47df.js" as="script"><link rel="preload" href="/assets/js/26.c3d4b548.js" as="script"><link rel="prefetch" href="/assets/js/10.483f2013.js"><link rel="prefetch" href="/assets/js/11.981d4461.js"><link rel="prefetch" href="/assets/js/12.95d2c383.js"><link rel="prefetch" href="/assets/js/13.061c2fe0.js"><link rel="prefetch" href="/assets/js/14.ec2753db.js"><link rel="prefetch" href="/assets/js/15.8ba1c321.js"><link rel="prefetch" href="/assets/js/16.f7f0d34c.js"><link rel="prefetch" href="/assets/js/17.aac0bf62.js"><link rel="prefetch" href="/assets/js/18.2e2fe306.js"><link rel="prefetch" href="/assets/js/19.aee304b3.js"><link rel="prefetch" href="/assets/js/20.86a73bc1.js"><link rel="prefetch" href="/assets/js/21.8992c972.js"><link rel="prefetch" href="/assets/js/22.0a78500a.js"><link rel="prefetch" href="/assets/js/23.06342909.js"><link rel="prefetch" href="/assets/js/24.06fd96a3.js"><link rel="prefetch" href="/assets/js/25.00664d4e.js"><link rel="prefetch" href="/assets/js/27.3c6927ad.js"><link rel="prefetch" href="/assets/js/28.74498c0b.js"><link rel="prefetch" href="/assets/js/29.aae1a826.js"><link rel="prefetch" href="/assets/js/3.4d2bdca7.js"><link rel="prefetch" href="/assets/js/30.c7732a2c.js"><link rel="prefetch" href="/assets/js/31.20403043.js"><link rel="prefetch" href="/assets/js/32.7b8e9cfe.js"><link rel="prefetch" href="/assets/js/33.8610da11.js"><link rel="prefetch" href="/assets/js/4.d7b1015b.js"><link rel="prefetch" href="/assets/js/5.ff87de2e.js"><link rel="prefetch" href="/assets/js/6.0e91e688.js"><link rel="prefetch" href="/assets/js/7.ba30e213.js"><link rel="prefetch" href="/assets/js/8.35122549.js"><link rel="prefetch" href="/assets/js/9.081b18e5.js">
    <link rel="stylesheet" href="/assets/css/0.styles.6834c255.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="ant-row"><div class="sidebar-button"><i aria-label="icon: bars" class="anticon anticon-bars"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="bars" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg></i> <span></span></div> <div class="ant-col ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-5 ant-col-xl-5 ant-col-xxl-4"><a href="/" class="router-link-active no-logo home-link"><!----> <span class="site-name">CatchAdmin 官网</span></a> <div class="search-box mobile-search"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div></div> <div class="ant-col ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-19 ant-col-xl-19 ant-col-xxl-20"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><ul role="menu" id="nav" class="ant-menu ant-menu-horizontal ant-menu-root ant-menu-light"><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/" class="router-link-active">
          🏠首页
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/docs/">
          📖文档
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item ant-menu-item-selected"><a href="/laravel/" class="router-link-active">
          📖Laravel
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/faq/">
          🤔FAQ
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/donate/">
          🎉赞助名单
        </a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>
          🚀仓库地址
        </span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="visibility:hidden;position:absolute;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li></ul> <!----></nav></div></div> <!----></header> <aside class="sidebar"><div><div class="ads"><div id="ads_1"><img src="https://cover.kancloud.cn/akasishikelu/thinkphp6!middle"> <span title="基于 catchadmin 的 Thinkphp 6.0 企业级后台管理开发&amp;源码分析">基于 catchadmin 的 Thinkphp 6.0 企业级后台管理开发&amp;源码分析</span></div></div> <div role="separator" id="reset-margin" class="ant-divider ant-divider-horizontal ant-divider-dashed"></div></div> <ul class="sidebar-links"><li><a href="/laravel/" aria-current="page" title="介绍" class="sidebar-link">介绍</a></li><li><a href="/laravel/install.html" title="项目安装" class="sidebar-link">项目安装</a></li><li><a href="/laravel/module.html" title="模块" class="sidebar-link">模块</a></li><li><a href="/laravel/model.html" title="模型" class="sidebar-link">模型</a></li><li><a href="/laravel/console.html" title="命令" class="sidebar-link">命令</a></li><li><a href="/laravel/form.html" aria-current="page" title="表单" class="active sidebar-link">表单</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/laravel/form.html#area" title="Area" class="sidebar-link">Area</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#avatar" title="Avatar" class="sidebar-link">Avatar</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#date" title="Date" class="sidebar-link">Date</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#datetime" title="DateTime" class="sidebar-link">DateTime</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#text" title="Text" class="sidebar-link">Text</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#email" title="Email" class="sidebar-link">Email</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#fileupload" title="FileUpload" class="sidebar-link">FileUpload</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#imageupload" title="ImageUpload" class="sidebar-link">ImageUpload</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#password" title="Password" class="sidebar-link">Password</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#url" title="Url" class="sidebar-link">Url</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#textarea" title="TextArea" class="sidebar-link">TextArea</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#boolean" title="Boolean" class="sidebar-link">Boolean</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#number" title="Number" class="sidebar-link">Number</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#select" title="Select" class="sidebar-link">Select</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#selectmultiple" title="SelectMultiple" class="sidebar-link">SelectMultiple</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#editor" title="Editor" class="sidebar-link">Editor</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#tree" title="Tree" class="sidebar-link">Tree</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#验证" title="验证" class="sidebar-link">验证</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#事件" title="事件" class="sidebar-link">事件</a></li><li class="sidebar-sub-header"><a href="/laravel/form.html#🔧-额外的非常有用的-api" title="🔧 额外的非常有用的 API" class="sidebar-link">🔧 额外的非常有用的 API</a></li></ul></li><li><a href="/laravel/table.html" title="表格组件" class="sidebar-link">表格组件</a></li><li><a href="/laravel/macros.html" title="扩展方法" class="sidebar-link">扩展方法</a></li><li><a href="/laravel/excel.html" title="Excel" class="sidebar-link">Excel</a></li><li><a href="/laravel/issue.html" title="常见问题" class="sidebar-link">常见问题</a></li></ul></aside> <main class="page"> <div class="theme-antdocs-content content__default"><h1 id="表单"><a href="#表单" class="header-anchor">#</a> 表单</h1> <p><code>Laravel</code>版本的表单稍稍与<code>TP</code>不同，针对不同表单的字段类型做了区分，更加语义化，使用起来会更加方便。那么下面看看提供了哪些字段类型。</p> <h2 id="area"><a href="#area" class="header-anchor">#</a> Area</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Area</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-hint">array</span> <span class="token variable">$props</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="avatar"><a href="#avatar" class="header-anchor">#</a> Avatar</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Avatar</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$action</span><span class="token punctuation">,</span> <span class="token keyword type-hint">bool</span> <span class="token variable">$auth</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="date"><a href="#date" class="header-anchor">#</a> Date</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Date</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div><p>需要范围时间</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Date</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">range</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="datetime"><a href="#datetime" class="header-anchor">#</a> DateTime</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">DateTime</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div><p>需要范围时间</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">DateTime</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">range</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="text"><a href="#text" class="header-anchor">#</a> Text</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Text</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>text 类型支持 input 框</p> <h2 id="email"><a href="#email" class="header-anchor">#</a> Email</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Email</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="fileupload"><a href="#fileupload" class="header-anchor">#</a> FileUpload</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">FileUpload</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$action</span><span class="token punctuation">,</span> <span class="token keyword type-hint">bool</span> <span class="token variable">$auth</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="单文件上传"><a href="#单文件上传" class="header-anchor">#</a> 单文件上传</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">FileUpload</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$action</span><span class="token punctuation">,</span> <span class="token keyword type-hint">bool</span> <span class="token variable">$auth</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">signle</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="imageupload"><a href="#imageupload" class="header-anchor">#</a> ImageUpload</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">ImageUpload</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$action</span><span class="token punctuation">,</span> <span class="token keyword type-hint">bool</span> <span class="token variable">$auth</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="单图上传"><a href="#单图上传" class="header-anchor">#</a> 单图上传</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">ImageUpload</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$action</span><span class="token punctuation">,</span> <span class="token keyword type-hint">bool</span> <span class="token variable">$auth</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">signle</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="password"><a href="#password" class="header-anchor">#</a> Password</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Password</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="url"><a href="#url" class="header-anchor">#</a> Url</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Url</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="textarea"><a href="#textarea" class="header-anchor">#</a> TextArea</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">TextArea</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="boolean"><a href="#boolean" class="header-anchor">#</a> Boolean</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Boolean</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="number"><a href="#number" class="header-anchor">#</a> Number</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Number</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="select"><a href="#select" class="header-anchor">#</a> Select</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Select</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-declaration">array</span><span class="token operator">|</span><span class="token class-name">Collection</span> <span class="token variable">$options</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="selectmultiple"><a href="#selectmultiple" class="header-anchor">#</a> SelectMultiple</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">SelectMultiple</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">,</span> <span class="token keyword type-declaration">array</span><span class="token operator">|</span><span class="token class-name">Collection</span> <span class="token variable">$options</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="editor"><a href="#editor" class="header-anchor">#</a> Editor</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Editor</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="tree"><a href="#tree" class="header-anchor">#</a> Tree</h2> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Tree</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$name</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$title</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="验证"><a href="#验证" class="header-anchor">#</a> 验证</h2> <ul><li><code>validateStr</code>: 字符串</li> <li><code>validateArr</code>: 数组</li> <li><code>validateNum</code>: 数字类型</li> <li><code>validateDate</code>: 日期类型</li> <li><code>validateInt</code>: 整型</li> <li><code>validateFloat</code>: 浮点数</li> <li><code>validateObject</code>: 对象</li> <li><code>validateEmail</code>: 邮箱</li> <li><code>validateEnum</code>: enum</li> <li><code>validateUrl</code>: URL</li> <li><code>validateHex</code></li> <li><code>validatePattern</code>: 正则验证</li> <li><code>validateAlpha</code>: 必须为纯字母</li> <li><code>validateAlphaNum</code>: 必须为字母和数字</li> <li><code>validateAlphaDash</code>: 必须为字母和数字，下划线_及破折号-</li> <li><code>validateMobile</code>: 手机号</li> <li><code>validateIdCard</code>: 身份证</li> <li><code>validateZip</code>: 邮政编码</li> <li><code>validateIp</code>: ip 地址</li> <li><code>validateLandLine</code>: 座机格式</li> <li><code>validatePassword</code>: 以字母开头，长度在6~18之间，只能包含字母、数字和下划线</li> <li><code>validateStrongPassword</code>: 必须包含大小写字母和数字的组合，不能使用特殊字符，长度在8-20之间</li> <li><code>validateChineseCharacter</code>: 必须为纯汉字</li></ul> <p>除了直接调用这些验证方法外，还额外提供更加方便的方式做验证. 例如</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token class-name static-context">Text</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'mobile'</span><span class="token punctuation">,</span> 手机号<span class="token punctuation">)</span><span class="token operator">-&gt;</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'string|mobile'</span><span class="token punctuation">)</span>
</code></pre></div><p>如果需要多个验证使用 <code>|</code> 隔开。 下面的的 <code>key</code> 代表可用的验证字符</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token string single-quoted-string">'string'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateStr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'array'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateArr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'number'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateNum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'date'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateDate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'int'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateInt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'float'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateFloat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'object'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'email'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateEmail</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'enum'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateEnum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'url'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateUrl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'hex'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateHex</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'alpha'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateAlpha</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'alphaNum'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateAlphaNum</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'alphaDash'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateAlphaDash</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'mobile'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateMobile</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'idCard'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateIdCard</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'zip'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateZip</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'ip'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateIp</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'landLine'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateLandLine</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'password'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validatePassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'strongPassword'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateStrongPassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token string single-quoted-string">'chinese'</span> <span class="token operator">=&gt;</span> <span class="token class-name static-context">ValidateFactory</span><span class="token operator">::</span><span class="token function">validateChineseCharacter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
</code></pre></div><h2 id="事件"><a href="#事件" class="header-anchor">#</a> 事件</h2> <ul><li><code>beforeSave</code> 保存前</li> <li><code>afterSave</code> 保存后</li> <li><code>beforeUpdate</code> 更新前</li> <li><code>afterUpdate</code> 更新后</li> <li><code>beforeDestroy</code> 删除前</li> <li><code>afterDestroy</code> 删除后</li></ul> <p>如果表单需要在保存前做某些事情的话，那么可以这么做。</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CatchFom</span><span class="token punctuation">;</span>

<span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">beforeSave</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$form</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// todo something</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><p>其他事件也是类似。其实这样的事件可以用<code>模型事件</code>代替，一样可以达到效果, 看个人选择了。除了以上这几个事件外，还提供了</p> <ul><li><code>prepare</code>
这个事件主要用于<code>验证数据</code>，这个事件是在注入时便运行了。所以它是在上面几个事件前执行的。</li></ul> <h2 id="🔧-额外的非常有用的-api"><a href="#🔧-额外的非常有用的-api" class="header-anchor">#</a> 🔧 额外的非常有用的 API</h2> <h3 id="when-bool-condition-callback"><a href="#when-bool-condition-callback" class="header-anchor">#</a> when(bool $condition, $callback)</h3> <p>当满足 <code>condition</code> 时，执行 <code>callback</code></p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">when</span><span class="token punctuation">(</span><span class="token constant boolean">true</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$form</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// todo something</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="getdata"><a href="#getdata" class="header-anchor">#</a> getData()</h3> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>这个访问可以获取表单的数据。例如表单数据是下面的数据</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token keyword">return</span> <span class="token punctuation">[</span>
    <span class="token string single-quoted-string">'best'</span> <span class="token operator">=&gt;</span> <span class="token string single-quoted-string">'catchadmin'</span>
<span class="token punctuation">]</span>
</code></pre></div><p>通过 <code>getData</code> 你可以获取到这个数组。如果需要获取某个字段。可以这样</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token property">best</span>
</code></pre></div><p>OR</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'best'</span><span class="token punctuation">]</span>
</code></pre></div><h3 id="setdata-array-data"><a href="#setdata-array-data" class="header-anchor">#</a> setData(array $data)</h3> <p>如果表单的数据不足以满足保存时，需要添加额外的数据，那么可以用 <code>setData</code> 补充额外的数据</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">setData</span><span class="token punctuation">(</span><span class="token variable">$data</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h3 id="getcondition"><a href="#getcondition" class="header-anchor">#</a> getCondition()</h3> <p>获取模型查询的条件</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">getCondition</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="setcondition-array-data"><a href="#setcondition-array-data" class="header-anchor">#</a> setCondition(array $data)</h3> <p>设置模型查询的条件</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">setCondition</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="getmodel"><a href="#getmodel" class="header-anchor">#</a> getModel()</h3> <p>获取当前 Form 使用的模型</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">getModel</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="getprimarykeyvalue"><a href="#getprimarykeyvalue" class="header-anchor">#</a> getPrimaryKeyValue()</h3> <p>获取模型的主键值</p> <div class="language-php extra-class"><pre class="language-php"><code><span class="token variable">$form</span><span class="token operator">-&gt;</span><span class="token function">getPrimaryKeyValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/catch-admin/document/edit/master/docs/laravel/form.md" target="_blank" rel="noopener noreferrer">在 Github 编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/laravel/console.html" class="prev"><i aria-label="icon: left" class="anticon anticon-left"><svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></i>
        命令
      </a></span> <span class="next"><a href="/laravel/table.html">
        表格组件
        <i aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></a></span></p></div> </main> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.d0396f44.js" defer></script><script src="/assets/js/2.1cef47df.js" defer></script><script src="/assets/js/26.c3d4b548.js" defer></script>
  </body>
</html>